import { commonTableOptions } from '@/utils/util'

export const tableOption = function () {
  let self = this
  return {
    ...commonTableOptions,
    indexFixed: false,
    menuFixed: false,
    menuWidth: 100,
    menu: true,
    header: true,
    searchMenuSpan: 6,
    searchLabelWidth: 0,
    viewBtn: false,
    viewBtnText: '详情',
    viewTitle: '详情',
    span: 24,
    // dialogCustomClass: 'crud-dialog',
    dialogWidth: '700px',
    // height: self?.documentHeight - 450,
    column: [
      {
        label: '标题',
        search: false,
        prop: 'messageName',
        hide: false,
        overHidden: true,
        formatter: (row) => {
          if (!row.messageName) return '--'
          return row.messageName
        }
      },
      {
        label: '内容',
        search: false,
        prop: 'messageContent',
        hide: false,
        overHidden: false,
        slot: true,
        width: 550,
        headerAlign: 'center',
        align: 'left'
      },
      {
        label: '接收船舶',
        prop: 'shipId',
        search: true,
        filterable: true,
        searchOrder: 1,
        // multiple: true,
        type: 'select',
        hide: true,
        dicData: self.shipList,
        props: {
          label: 'shipName',
          value: 'shipId'
        }
      },
      {
        label: '发送船舶数',
        search: false,
        prop: 'shipName',
        hide: false,
        overHidden: true,
        formatter: (row) => {
          if (!row.receiverList) return 0
          return row.receiverList.length
        }
      },
      {
        label: '状态',
        prop: 'sendStatus',
        hide: false,
        search: true,
        type: 'select',
        searchOrder: 0,
        dicData: [
          {
            label: '待发送',
            value: 0
          },
          {
            label: '已发送',
            value: 1
          },
          {
            label: '部分接收',
            value: 2
          },
          {
            label: '全部接收',
            value: 3
          }
        ]
      },
      {
        label: '接收进度',
        search: false,
        prop: 'acceptanceRate',
        hide: false,
        overHidden: true,
        width: 200,
        align: 'left',
        headerAlign: 'center'
        // formatter: (row) => {
        //   if (!row.acceptanceRate) return '0'
        //   return (row.acceptanceRate * 100).toFixed(2)
        // }
      },
      {
        label: '发送人',
        search: false,
        prop: 'sendUserName',
        hide: false,
        overHidden: true,
        maxlength: 20
      },
      {
        label: '发送时间',
        search: true,
        searchOrder: 2,
        prop: 'sendTime',
        type: 'datetime',
        format: 'yyyy-MM-dd HH:mm:ss',
        valueFormat: 'yyyy-MM-dd HH:mm:ss',
        startPlaceholder: '发送开始时间',
        endPlaceholder: '发送结束时间',
        defaultTime: ['00:00:00', '23:59:59'],
        searchRange: true,
        editDisplay: false,
        addDisplay: false
      }
    ]
  }
}

export const formOption = function () {
  let self = this
  return {
    disabled: self.isDisabled,
    border: true,
    index: true,
    indexLabel: '序号',
    stripe: true,
    menuAlign: 'center',
    align: 'center',
    viewBtn: false,
    submitBtn: false,
    card: false,
    columnBtn: false,
    // menuWidth: 300,
    // dialogClickModal: false,
    // indexWidth: 90,
    // labelWidth: 100,
    // searchIcon: false,
    // refreshBtn: false,
    // searchMenuPosition: "right",
    // searchBtnText: "查 询",
    // labelPosition: "right",
    gutter: 24,
    span: 24,
    emptyBtn: false,
    menu: false,
    dialogCustomClass: 'crud-dialog',
    column: [
      {
        label: '标题',
        search: false,
        prop: 'messageName',
        hide: false,
        overHidden: true,
        type: 'input',
        maxlength: 20,
        rules: [
          {
            required: true,
            message: '标题不能为空',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '内容',
        search: false,
        prop: 'messageContent',
        hide: false,
        overHidden: true,
        type: 'textarea',
        minLength: 1,
        maxlength: 100,
        rules: [
          {
            required: true,
            message: '内容不能为空',
            trigger: 'blur'
          },
          { min: 1, max: 140, message: '长度在 1 到 100 个字符', trigger: 'blur' }
        ]
      },
      {
        label: '选择船舶',
        prop: 'shipIds',
        multiple: true,
        filterable: true,
        type: 'select',
        dicData: self.tenantCatShip,
        props: {
          label: 'shipName',
          value: 'shipId'
        },
        rules: [{ required: true, message: '船舶不能为空', trigger: 'change' }],
        change(val) {
          if (val.value.includes('all')) {
            self.$nextTick(() => {
              self.form.shipIds = self.tenantCatShipAll
            })
          }
        }
      }
    ]
  }
}
